<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Jhin" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="ONex B2B2C 二次开发 序章前言对应 ECShop ECStore 相信很多人并不默认，做二次开发的也很多，不才之前做过ecshop的二次开发，本次开始学习 Onex b2b2c 版本的二次开发。相比较而言，ONex 和 ecstore的 文件结构是很像的，但前者可能更复杂一些。">
<meta property="og:type" content="article">
<meta property="og:title" content="ONex B2B2C 二次开发 序章">
<meta property="og:url" content="http://jhin.oschina.io/ShopEX/2016-10-21-01.ONex B2B2C 二次开发之序章.html">
<meta property="og:site_name" content="Jhin">
<meta property="og:description" content="ONex B2B2C 二次开发 序章前言对应 ECShop ECStore 相信很多人并不默认，做二次开发的也很多，不才之前做过ecshop的二次开发，本次开始学习 Onex b2b2c 版本的二次开发。相比较而言，ONex 和 ecstore的 文件结构是很像的，但前者可能更复杂一些。">
<meta property="og:updated_time" content="2016-12-22T01:49:58.635Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ONex B2B2C 二次开发 序章">
<meta name="twitter:description" content="ONex B2B2C 二次开发 序章前言对应 ECShop ECStore 相信很多人并不默认，做二次开发的也很多，不才之前做过ecshop的二次开发，本次开始学习 Onex b2b2c 版本的二次开发。相比较而言，ONex 和 ecstore的 文件结构是很像的，但前者可能更复杂一些。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://jhin.oschina.io/ShopEX/2016-10-21-01.ONex B2B2C 二次开发之序章.html"/>


  <title> ONex B2B2C 二次开发 序章 | Jhin </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Jhin</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Jhin(ijhin@sina.com)</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-thinkphp">
          <a href="/categories/ThinkPHP-DOC" rel="section">
            
            ThinkPHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-mysql">
          <a href="/categories/MySQL" rel="section">
            
            MySQL
          </a>
        </li>
      
        
        <li class="menu-item menu-item-php">
          <a href="/categories/PHP" rel="section">
            
            PHP
          </a>
        </li>
      
        
        <li class="menu-item menu-item-linux">
          <a href="/categories/Linux" rel="section">
            
            Linux
          </a>
        </li>
      
        
        <li class="menu-item menu-item-nginx">
          <a href="/categories/Nginx" rel="section">
            
            Nginx
          </a>
        </li>
      
        
        <li class="menu-item menu-item-html">
          <a href="/categories/HTML" rel="section">
            
            HTML5
          </a>
        </li>
      
        
        <li class="menu-item menu-item-javascript">
          <a href="/categories/JavaScript" rel="section">
            
            JavaScript
          </a>
        </li>
      
        
        <li class="menu-item menu-item-onex">
          <a href="/categories/ONEX" rel="section">
            
            ONEX
          </a>
        </li>
      
        
        <li class="menu-item menu-item-yii">
          <a href="/categories/Yii2" rel="section">
            
            Yii2
          </a>
        </li>
      
        
        <li class="menu-item menu-item-shopex">
          <a href="/categories/ShopEX" rel="section">
            
            ShopEX
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                ONex B2B2C 二次开发 序章
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-10-21T14:51:55+08:00" content="2016-10-21">
              2016-10-21
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/ShopEX/" itemprop="url" rel="index">
                    <span itemprop="name">ShopEX</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="ONex-B2B2C-二次开发-序章"><a href="#ONex-B2B2C-二次开发-序章" class="headerlink" title="ONex B2B2C 二次开发 序章"></a>ONex B2B2C 二次开发 序章</h2><h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>对应 ECShop ECStore 相信很多人并不默认，做二次开发的也很多，不才之前做过ecshop的二次开发，本次开始学习 Onex b2b2c 版本的二次开发。相比较而言，ONex 和 ecstore的 文件结构是很像的，但前者可能更复杂一些。</p>
<a id="more"></a>
<h3 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h3><p>bbc</p>
<p>|- index.php                  web访问入口文件<br>|- .htaccess                 apache支持的目录配置文件,作用是让Ecos支持url rewrite, 可参考Apache重写指南<br>|- license.txt                 ShopEx的软件授权协议<br>|- readme.txt                 Ecos简要说明<br>|- app                         系统里的所有app都在放置在这个目录下, 每个app单独目录存放<br>|  |- {$app_name}             app_name代表一个具体的app, 例如:base<br>|  |  |- dbschema             {$app_name}的数据库表定义文件<br>|  |  |- docs                 {$app_name}的帮助文件, 格式为t2t. 如果安装了desktop app和dev    app则会在后台桌面上看到所有系统里app所提供的帮助文件<br>|  |  |- lang                 {$app_name}的多语言包<br>|  |  |- lib                {$app_name}的library库<br>|  |  |- model                {$app_name}的model文件<br>|  |  |- controller         {$app_name}的控制器文件<br>|  |  |- statics             {$app_name}的静态文件, 例如css/gif等<br>|  |  |- testcase             {$app_name}的测试用例<br>|  |  |- xmlschema             {$app_name}所支持的xml的定义文件, 文件格式为xsd<br>|  |  |- widgets             {$app_name}存放本app定义的所有挂件, 每一个目录代表一个widget. 在app安装时安装到系统<br>|  |  |- app.xml             {$app_name}的app定义文件, 文件定义:app/base/xmlschema/app.xsd<br>|  |  |- services.xml         {app_name}的service定义文件, {$app_name}的service box及service配置文件,文件定义:app/base/xmlschema/services.xsd<br>|  |  |- icon.png             {$app_name}的图标, 当系统应用setup app进行安装时, 可以在安装过程中看到<br>|  |  |- desktop.xml         {$app_name}的后台配置文件, 文件定义:app/desktop/xmlschema/desktop.xsd<br>|  |  |- task.php             {$app_name}本app的应用维护程序, 所包含的全部是回调函数. 包含pre_install/post_install/pre_update/post_update等<br>|  |  |- setting.php         {$app_name}所提供的初始化setting数据<br>|- config                     存放系统的配置文件<br>|  |- config.php             系统配置文件. 包含数据库配置, 目录配置, session配置等<br>|  |- deploy.xml                  系统部署配置文件, 如果系统想通过setup app进行安装, 需要配置此文件. 文件定义:app/base/xmlschema/deploy.xsd<br>|  |- install.lock.php         安装锁定文件. 如果系统开始安装任何app则生成此文件. 如果系统依赖于setup app进行安装, 当发现有install.lock.php则拒绝安装, 除非手动删除此文件. 例如:Ecstore<br>|  |- mapper.php               路由配置文件<br>|  |- certi.php             ShopEx证书<br>|- customize                二次开发目录<br>|- demo                        演示数据<br>|- data                      数据目录<br>|- public                    公用文件目录<br>|- themes                    模板目录</p>
<h3 id="二次开发"><a href="#二次开发" class="headerlink" title="二次开发"></a>二次开发</h3><h4 id="配置二次开发目录"><a href="#配置二次开发目录" class="headerlink" title="配置二次开发目录"></a>配置二次开发目录</h4><p>将 <code>config/compatible.php</code> 复制到 <code>config/production/compatible.php</code> 并且修改配置。</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span></div><div class="line">	<span class="comment">//二次开发目录设置，`custom` 可以替换为自己的二次开发目录</span></div><div class="line">	<span class="comment">//如果该配置已开启，并且有对应的目录，则表示已经开启二次开发目录</span></div><div class="line"></div><div class="line">	define(<span class="string">'CUSTOM_CORE_DIR'</span>, ROOT_DIR.<span class="string">'/custom'</span>);</div></pre></td></tr></table></figure>
<p>新建目录 <code>custom</code>，需要和<code>app</code>目录同级。</p>
<h4 id="自定义路由"><a href="#自定义路由" class="headerlink" title="自定义路由"></a>自定义路由</h4><p>默认的路由文件为<code>bootstrap/routes.php</code>，在二次开发时可以创建<code>bootstrap/custom_routes.php</code>，这时系统将不再加载 <code>bootstrap/routes.php</code>文件。</p>
<p>因此有两种方式进行二次开发</p>
<p>1、在对路由修改较少的情况下，在 <code>bootstrap/custom_routes.php</code> 中 <code>include &#39;bootstrap/routes.php&#39;</code>，然后遵循路由的规则进行增量 添加。</p>
<p>2、当对路由进行很大规模的调整，完整的 <b>copy</b> <code>bootstrap/routes.php</code> 内容到 <code>bootstrap/custom_routes.php</code>，然后在此基础上修改。</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// 二次开发目录</span></div><div class="line"></div><div class="line"><span class="comment">// 自定义页面路由</span></div><div class="line">route::group(<span class="keyword">array</span>(), <span class="function"><span class="keyword">function</span><span class="params">()</span></span>&#123;</div><div class="line">    route::get(<span class="string">'custom-act.html'</span>, [ <span class="string">'uses'</span> =&gt; <span class="string">'topc_ctl_act@index'</span>]);</div><div class="line">&#125;);</div><div class="line"></div><div class="line"><span class="comment">// 在文件底部添加即可。</span></div></pre></td></tr></table></figure>
<h4 id="自定义控制器"><a href="#自定义控制器" class="headerlink" title="自定义控制器"></a>自定义控制器</h4><p>新增控制器文件 <code>custom/topc/controller/act.php</code>，控制器名称根据路由的配置。（不存在的目录，请自行添加）</p>
<figure class="highlight php"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="meta">&lt;?php</span></div><div class="line"></div><div class="line"><span class="comment">/* </span></div><div class="line"> * To change this license header, choose License Headers in Project Properties.</div><div class="line"> * To change this template file, choose Tools | Templates</div><div class="line"> * and open the template in the editor.</div><div class="line"> */</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">topc_ctl_act</span> <span class="keyword">extends</span> <span class="title">topc_controller</span> </span>&#123;</div><div class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">(&amp;$app)</span> </span>&#123;</div><div class="line">        <span class="keyword">parent</span>::__construct();</div><div class="line">    &#125;</div><div class="line">    </div><div class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">index</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;page(<span class="string">'topc/act/index.html'</span>, $pagedata);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h4 id="自定义视图"><a href="#自定义视图" class="headerlink" title="自定义视图"></a>自定义视图</h4><p>新增自定义页面文件 <code>custom/topc/view/act/index.html</code></p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">&lt;div class="content"&gt;</div><div class="line">	这是 custom-act.html 的内容</div><div class="line">&lt;/div&gt;</div></pre></td></tr></table></figure>
      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/ShopEX/2016-10-21-04.ONex B2B2C 二次开发之商品扩展属性.html" rel="next" title="ONex B2B2C 二次开发 商品扩展属性">
                <i class="fa fa-chevron-left"></i> ONex B2B2C 二次开发 商品扩展属性
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/ShopEX/2016-10-21-14.ONex B2B2C 二次开发之cookie在挂件中的使用.html" rel="prev" title="ONex B2B2C 二次开发 cookie在挂件中的使用">
                ONex B2B2C 二次开发 cookie在挂件中的使用 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Jhin" />
          <p class="site-author-name" itemprop="name">Jhin</p>
          <p class="site-description motion-element" itemprop="description">Jhin 开发文档小结</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">22</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#ONex-B2B2C-二次开发-序章"><span class="nav-number">1.</span> <span class="nav-text">ONex B2B2C 二次开发 序章</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#目录结构"><span class="nav-number">1.2.</span> <span class="nav-text">目录结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#二次开发"><span class="nav-number">1.3.</span> <span class="nav-text">二次开发</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#配置二次开发目录"><span class="nav-number">1.3.1.</span> <span class="nav-text">配置二次开发目录</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#自定义路由"><span class="nav-number">1.3.2.</span> <span class="nav-text">自定义路由</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#自定义控制器"><span class="nav-number">1.3.3.</span> <span class="nav-text">自定义控制器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#自定义视图"><span class="nav-number">1.3.4.</span> <span class="nav-text">自定义视图</span></a></li></ol></li></ol></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Jhin</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="/">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="/">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
